﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Microsoft.Practices.Unity;
using Web.SystemConfig.Services;
using ePlanet.ArchiveMange.Services;
using System.Data;
using ePlanet.ArchiveMange.Models;
using System.Collections;
using DreamBuilder.Core.Container;
using Web.SystemConfig.WorkFlow;
using Web.SystemConfig.SysCache;
using ePlanet.ArchiveMange.Enum;

namespace Web.Views.ArchiveFlowView
{
    public partial class EquipArchiveView : ArchiveFlowEditPageBase
    {
        #region 属性变量
        [Dependency]
        public ICodeTable CodeTableService
        {
            get;
            set;
        }

        [Dependency]
        public IArchiveMenuService ArchiveMenuService
        {
            get;
            set;
        }

        [Dependency]
        public IPageFileService PageFileService
        {
            get;
            set;
        }

        [Dependency]
        public IAuth_Org orgService
        {
            get;
            set;
        }

        [Dependency]
        public IEquipmentService EquipmentService
        {
            get;
            set;
        }

        public string archiveTypeName;
        /// <summary>
        /// 档案类型
        /// </summary>
        public string ReqArchiveType
        {
            get
            {
                if (this.Request.QueryString["archiveType"] != null)
                {
                    return this.Request.QueryString["archiveType"];
                }
                else
                {
                    throw new Exception("档案类型不能为空");
                }
            }
        }


        #endregion

        #region 页面初始化
        protected void Page_Load(object sender, EventArgs e)
        {
            this.CurrentPageState = PageState.State_Edit;
            if (!IsPostBack)
            {
                ArchiveMangeModal.EQUIPMENT_ARCHIVEDataTable documentArchiveTable = EquipmentService.GetAllDocumenArchivetDataById(ArchiveID);
                if (documentArchiveTable != null && documentArchiveTable.Rows.Count > 0)
                {
                    ArchiveMangeModal.EQUIPMENT_ARCHIVERow row = documentArchiveTable.Rows[0] as ArchiveMangeModal.EQUIPMENT_ARCHIVERow;
                    GetPrivilege(CurrentArchiveKind, row.DATAID, row.STATUSID.ToString());

                }
                else
                {
                    Alert("未找到相应数据！");
                    GoBack();
                }
                if (!canView)
                {
                    Alert("您无权查看该数据！");
                    GoBack();
                }
                if (!canOperate)
                {
                    this.btnAddArchiveBack.Visible = false;
                    this.btnDeletePageFile.Visible = false;
                    this.btnRemovePageFile.Visible = false;
                    this.btnSavePageFileOrder.Visible = false;
                }
                if (!showReturn)
                    this.btnBack.Visible = false;
                if (this.gv_PageFileView.SelectItems.Count > 0)
                {
                    this.btnRemovePageFile.Attributes["onclick"] = "javascript:return confirm('确定要从卷里移除选中的件吗?');";
                    this.btnDeletePageFile.Attributes["onclick"] = "javascript:return confirm('删除操作不能恢复,确定要删除吗?');";
                }
                else
                {
                    string Altmsg = "javascript:alert('未选中任何项!'); return false";
                    this.btnRemovePageFile.Attributes["onclick"] = Altmsg;
                    this.btnDeletePageFile.Attributes["onclick"] = Altmsg;
                }
                this.attachArchive.ObjectID = ArchiveID;
                this.attachArchive.ObjectTableName = "";
                AddAttachmentInfos();
                InitControls();
                LoadHidden();
                LoadData();
                LoadArchivePageFile();
                LoadApproveData();
                SetButtonVisable();
            }
        }

        /// <summary>
        /// 初始化数据项
        /// </summary>
        private void InitControls()
        {

            //保密期限
            DataSet keepSecurityTime = CodeTableService.GetCodeTableDataByType("KeepSecurityTime");
            if (keepSecurityTime != null && keepSecurityTime.Tables.Count > 0)
            {
                this.ddlKeepSecurityTime.DataSource = keepSecurityTime;
                this.ddlKeepSecurityTime.DataTextField = "Code_Desc";
                this.ddlKeepSecurityTime.DataValueField = "CodeTableID";
                this.ddlKeepSecurityTime.DataBind();
                this.ddlKeepSecurityTime.Items.Insert(0, new ListItem("--请选择--", "-1"));
            }

            DataSet KeepTime = CodeTableService.GetCodeTableDataByType("KeepTime");
            if (KeepTime != null && KeepTime.Tables.Count > 0)
            {
                this.ddlKeepTime.DataSource = KeepTime;
                this.ddlKeepTime.DataTextField = "Code_Desc";
                this.ddlKeepTime.DataValueField = "CodeTableID";
                this.ddlKeepTime.DataBind();
                this.ddlKeepTime.Items.Insert(0, new ListItem("--请选择--", "-1"));
            }
            DataSet CarrierType = CodeTableService.GetCodeTableDataByType("CarrierType");
            if (CarrierType != null && CarrierType.Tables.Count > 0)
            {
                this.ddlCarrierType.DataSource = CarrierType;
                this.ddlCarrierType.DataTextField = "Code_Desc";
                this.ddlCarrierType.DataValueField = "CodeTableID";
                this.ddlCarrierType.DataBind();
                this.ddlCarrierType.Items.Insert(0, new ListItem("--请选择--", "-1"));
            }

            DataSet SecurityData = CodeTableService.GetCodeTableDataByType("SecurityType");
            if (CarrierType != null && CarrierType.Tables.Count > 0)
            {
                this.ddlSecurity.DataSource = SecurityData;
                this.ddlSecurity.DataTextField = "Code_Desc";
                this.ddlSecurity.DataValueField = "CodeTableID";
                this.ddlSecurity.DataBind();
                this.ddlSecurity.Items.Insert(0, new ListItem("--请选择--", "-1"));
            }

            DataSet AccountTypeData = CodeTableService.GetCodeTableDataByType("AccountType");

            ArchiveMangeModal.ARCHIVEMENUDataTable dtArchiveMenu = ArchiveMenuService.GetArchiveMenuById(ReqArchiveType);
            if (dtArchiveMenu != null && dtArchiveMenu.Rows.Count > 0)
            {
                this.txtArchiveType.Text = (dtArchiveMenu.Rows[0] as ArchiveMangeModal.ARCHIVEMENURow).TYPECODE;
                this.archiveTypeName = (dtArchiveMenu.Rows[0] as ArchiveMangeModal.ARCHIVEMENURow).ARCHIVEMENU;
            }
            //来源
            this.txtArchiveSource.Text = "在线录入__档案整理";
            this.txtFileOrgName.Text = "厂中心档案室";
            this.txtBoxNum.Text = "未装盒";
            this.h_FileOrgID.Value = CommonUtil.GetConfigValue("ArchiveManage", "DefalutApproveOrgID");

            this.txtArchiveNum.Enabled = false;
            this.txtArchiveSource.Enabled = false;
            this.txtFullFondsNum.Enabled = false;
            this.txtArchiveType.Enabled = false;
            this.txtFilTime.Enabled = false;

            this.h_ArchiveTypeId.Value = ReqArchiveType;
        }

        private void LoadHidden()
        {
            if (Request.QueryString["archiveId"] != null)
            {
                h_arcvhive.Value = ArchiveID;
            }
            h_archiveType.Value = ReqArchiveType;
        }

        /// <summary>
        /// 设置按钮的可见性
        /// </summary>
        private void SetButtonVisable()
        {
            if (this.CurrentPageState == PageState.State_New)
            {
                this.btnDeletePageFile.Visible = false;
                this.btnRemovePageFile.Visible = false;
                //this.btnSavePageFileOrder.Visible = false;
            }
        }

        /// <summary>
        /// 加载数据
        /// </summary>
        private void LoadData()
        {
            IEquipmentService DocumentArchiveService = UContainer.Resolve<IEquipmentService>();
            ArchiveMangeModal.EQUIPMENT_ARCHIVEDataTable dt = DocumentArchiveService.GetAllDocumenArchivetDataById(ArchiveID);
            if (dt.Rows.Count > 0)
            {
                this.CurrentPageState = PageState.State_Edit;
                ArchiveMangeModal.EQUIPMENT_ARCHIVERow row = dt.Rows[0] as ArchiveMangeModal.EQUIPMENT_ARCHIVERow;
                this.txtArchiveNum.Text = row.ARCHIVENUM;
                this.txtArchiveSource.Text = row.ARCHIVESOURCE;
                ArchiveMangeModal.ARCHIVEMENUDataTable dtMenu = ArchiveMenuService.GetArchiveMenuById(row.ARCHIVETYPE.ToString());
                ArchiveMangeModal.ARCHIVEMENURow drMenu = dtMenu.Rows[0] as ArchiveMangeModal.ARCHIVEMENURow;
                this.txtArchiveType.Text = drMenu.ARCHIVEMENU;
                this.h_ArchiveTypeId.Value = row.ARCHIVETYPE.ToString();
                this.txtBoxNum.Text = row.BOXNUM;
                //DataTable dtOrg = orgService.GetORGInfo(row.FILEORGID);
                //this.txtFileOrgName.Text = dtOrg.Rows[0]["Org_Name"].ToString();
                //this.h_FileOrgID.Value = row.FILEORGID;
                //归档单位改为明文
                this.txtFileOrgName.Text = row.FILEORGID;
                if (!row.IsFILETIMENull())
                {
                    this.txtFilTime.Text = row.FILETIME.ToString("yyyy-MM-dd");
                }
                this.txtFullFondsNum.Text = row.FULLFONDSNUM;
                this.txtMainBodyNum.Text = row.MAINBODYNUM.ToString();
                this.txtPublishOrgID.Text = row.PUBLISHORGID;
                this.txtFileNum.Text = row.IsFILENUMNull() ? "" : row.FILENUM.ToString();
                this.txtPageNum.Text = row.PAGENUM.ToString();
                this.txtRemark.Text = row.REMARK;
                this.txtStartTime.Text = row.STARTTIME.ToString("yyyy-MM-dd");
                this.txtEndTime.Text = row.ENDTIME.ToString("yyyy-MM-dd");
                this.txtSummary.Text = row.SUMMARY;
                this.txtTitle.Text = row.TITLE;
                this.ddlCarrierType.SelectedValue = row.F_CARRIERTYPE;
                this.ddlKeepTime.SelectedValue = row.F_KEEPTIME;
                this.ddlSecurity.SelectedValue = row.F_SECURITYTYPE;
                this.txtStorageType.Text = row.STORAGETYPE;
                this.txtHUjianhao.Text = row.HUJIANHAO;
                this.txtStorageType.Text = row.STORAGETYPE;
                this.txtTypeNum.Text = row.TYPENUM;
                this.ddlKeepSecurityTime.SelectedValue = row.F_KEEPSECURITYTIME;
            }
        }

        /// <summary>
        /// 加载卷内件
        /// </summary>
        private void LoadArchivePageFile()
        {
            //加载刚编辑好的卷内件
            DataTable dtPageFile = null;
            IList<string> list = new
            List<string>();
            List<string> HasList = null;
            //卷内件数据
            if (Session["ArchivePageFile"] != null)
            {
                Hashtable ht = (Hashtable)Session["ArchivePageFile"];
                if (ViewState["HasFileList"] != null)
                {
                    HasList = (List<string>)ViewState["HasFileList"];
                }
                else
                {
                    HasList = new List<string>();
                }
                //Key是PageFileId，Value是ArchiveType
                foreach (string key in ht.Keys)
                {
                    if (ht[key].ToString() == ReqArchiveType) //找出包含此类型的卷内件ID
                    {
                        if (!HasList.Contains(key))  //判断空卷内件是否已经加入列表,没加入的加入列
                        {
                            //同时加入已经加入的列表
                            HasList.Add(key);
                        }
                    }
                }
                dtPageFile = PageFileService.GetPageFileByFileIdList(HasList);
                Session.Remove("ArchivePageFile");
                ViewState["HasFileList"] = HasList;//更新视图状态
            }
            //加载已经有的卷内件
            IEquipmentService equip = UContainer.Resolve<IEquipmentService>();
            DataTable dt2 = equip.GetPageFileByDATAID(ArchiveID);
            if (dtPageFile != null)
            {
                dtPageFile.Merge(dt2);
            }
            else
            {
                dtPageFile = dt2;
            }
            dtPageFile.TableName = "pagefile";
            this.gv_PageFileView.DataSource = dtPageFile;
            this.gv_PageFileView.DataBind();

        }

        /// <summary>
        /// 加载审核信息
        /// </summary>
        private void LoadApproveData()
        {

        }

        /// <summary>
        /// 附件实体增加更多信息
        /// </summary>
        private void AddAttachmentInfos()
        {
            Hashtable addInfos = new Hashtable();
            addInfos.Add("FunctionID", "0"); //功能ID(1：发文文档 2：发文附件 3：收文文档 4：收文附件 5：即时消息附件 6：新闻附件)
            addInfos.Add("FileTypeID", ""); //附件文件夹类型
            addInfos.Add("FileURL", ""); //附件存储路径
            addInfos.Add("IsXml", "0"); //是否XML代码化
            addInfos.Add("CreateUserID", this.CurrentUser.User_ID); //用户ID 目前可以写个固定的值作为测试
            addInfos.Add("Remark", "即时消息附件"); //备注
            if (Session["AddInfos"] == null)
            {
                Session.Add("AddInfos", addInfos);
            }
            else
            {
                Session.Remove("AddInfos");
                Session.Add("AddInfos", addInfos);
            }
        }
        #endregion

        #region 页面事件
        protected void gv_PageFileView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView drv = (DataRowView)e.Row.DataItem;
                System.Web.UI.WebControls.GridViewRow rows = ((GridViewRow)e.Row);
                string DataID = drv["DataID"].ToString();
                //int orderNum = Convert.ToInt32(drv["ORDERNUM"]);
                string url = "../ArchiveManage/PageFileEdit.aspx?archiveId=" + ArchiveID + "&archiveType=" + ReqArchiveType + "&DataID=" + DataID ;
                ((System.Web.UI.WebControls.Button)rows.FindControl("view")).Attributes["onclick"] = "javascript:openViewPage('" + url + "');return false;";
                string elecFileCount = ArchiveBusiHelper.Instance.GetPageFileTechnologyFileCount((int)ArchiveBaseType.Account, drv["dataid"].ToString());
                if (!string.IsNullOrEmpty(elecFileCount))
                {
                    e.Row.Cells[1].Text = string.Format("<img src='{0}' alt='{1}个电子文件' />",
                        "../../Images/qbz.jpg", elecFileCount);
                }
                else
                {
                    e.Row.Cells[1].Text = string.Empty;
                }
                e.Row.Cells[7].Text = CodeTableService.GetpkNameByCodepkValue(drv["F_SECURITYTYPE"].ToString());
                e.Row.Cells[8].Text = CodeTableService.GetpkNameByCodepkValue(drv["F_KEEPTIME"].ToString());
                e.Row.Cells[9].Text = orgService.GetOrgNameByOrgID(drv["FIleOrgID"].ToString());
                e.Row.Cells[11].Text = CodeTableService.GetpkNameByCodepkValue(drv["F_CARRIERTYPE"].ToString());
            }
        }

        protected void gv_PageFileView_RowCommond(object sender, GridViewCommandEventArgs e)
        {
            int RowIndex = Convert.ToInt32(e.CommandArgument);
            string pagefileId = gv_PageFileView.DataKeys[RowIndex].Value.ToString();
            switch (e.CommandName)
            {
                case "up":
                    if (RowIndex == 0)
                    {
                        this.ShowMsg("首记录不能上移");
                    }
                    else
                    {
                        //找出前一页的最后一个卷内件ID
                        string PrePagefileId = gv_PageFileView.DataKeys[RowIndex - 1].Value.ToString();
                        PageFileService.MovePageFileOrder(pagefileId, PrePagefileId);
                        LoadArchivePageFile();
                    }
                    break;
                case "down":
                    if (RowIndex == gv_PageFileView.DataKeys.Count - 1)
                    {
                        this.ShowMsg("尾记录不能下移");
                    }
                    else
                    {
                        //找出前一页的最后一个卷内件ID
                        string NexPagefileId = gv_PageFileView.DataKeys[RowIndex + 1].Value.ToString();
                        PageFileService.MovePageFileOrder(pagefileId, NexPagefileId);
                        LoadArchivePageFile();
                    }
                    break;
            }
        }
        #endregion

        #region 按钮事件
 

        /// 加载卷内件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnHid_Click(object sender, EventArgs e)
        {
            LoadArchivePageFile();
        }

        /// <summary>
        /// 保存并返回按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAddArchiveBack_Click(object sender, EventArgs e)
        {
            string errMsg = null;
            SaveData(ref errMsg);
            if (string.IsNullOrEmpty(errMsg))
            {
                Alert("保存成功！");
                if (!this.IsFromDataManage)
                {
                    GoBack();
                }
            }
            else
                Alert(errMsg);
        }

        /// <summary>
        /// 从卷内移除件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnRemovePageFile_Click(object sender, EventArgs e)
        {
            IPageFileService pageFile = UContainer.Resolve<IPageFileService>();
            List<string> HasList = (List<string>)ViewState["HasFileList"];
            foreach (string key in this.gv_PageFileView.SelectItems)
            {
                pageFile.RemoveData(key);
                //从视图状态中移除尚未保存的键
                if (HasList != null && HasList.Contains(key))
                {
                    HasList.Remove(key);
                }
            }
            ViewState["HasFileList"] = HasList;
            LoadArchivePageFile();
        }

        /// <summary>
        /// 彻底删除卷内件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDeletePageFile_Click(object sender, EventArgs e)
        {
            IPageFileService pageFile = UContainer.Resolve<IPageFileService>();
            List<string> HasList = (List<string>)ViewState["HasFileList"];
            foreach (string key in this.gv_PageFileView.SelectItems)
            {
                pageFile.DeleteData(key);
                //从视图状态中移除尚未保存的键
                if (HasList != null && HasList.Contains(key))
                {
                    HasList.Remove(key);
                }
            }
            ViewState["HasFileList"] = HasList;
            LoadArchivePageFile();
        }

        /// <summary>
        /// 保存卷内件序号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSavePageFileOrder_Click(object sender, EventArgs e)
        {
            HttpCookieCollection cookie = this.Request.Cookies;
            IPageFileService pageFile = UContainer.Resolve<IPageFileService>();
            int o_value = 0;
            foreach (string key in cookie.AllKeys)
            {
                if (int.TryParse(cookie[key].Value, out o_value))
                {
                    pageFile.ChangePageFileOrder(key, o_value);
                }
            }
            LoadArchivePageFile();
        }


        /// <summary>
        /// 返回按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnBack_Click(object sender, EventArgs e)
        {
            if (!this.IsFromDataManage)
            {
                GoBack();
            }
            else
            {
                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "window.close();", true);
            }
        }
        #endregion

        #region 页面方法

        private void SaveData(ref string errMsg)
        {
            IEquipmentService DocumentArchiveService = UContainer.Resolve<IEquipmentService>();
            if (string.IsNullOrEmpty(this.txtTitle.Text.Trim()))
            {
                errMsg = "标题不能为空!";
                return;
            }
            DateTime o_time = new DateTime();
            if (string.IsNullOrEmpty(this.txtStartTime.Text.Trim()) || !DateTime.TryParse(this.txtStartTime.Text.Trim(), out o_time))
            {
                errMsg = "起日期不能为空!";
                return;
            }
            if (string.IsNullOrEmpty(this.txtEndTime.Text.Trim()) || !DateTime.TryParse(this.txtEndTime.Text.Trim(), out o_time))
            {
                errMsg = "止日期不能为空!";
                return;
            }
            int s_out = 0;
            if (string.IsNullOrEmpty(this.txtPageNum.Text) || !int.TryParse(this.txtPageNum.Text.Trim(), out s_out))
            {
                errMsg = "页数不能为空!";
                return;
            }

            if (!string.IsNullOrEmpty(this.txtMainBodyNum.Text.Trim()) && !int.TryParse(this.txtMainBodyNum.Text.Trim(), out s_out))
            {
                errMsg = "正文输入格式不正确!";
                return;
            }
            if (this.ddlCarrierType.SelectedIndex < 1)
            {
                errMsg = "载体类型不能为空!";
                return;
            }
            if (this.ddlKeepTime.SelectedIndex < 1)
            {
                errMsg = "保管期限不能为空!";
                return;
            }
            if (this.ddlSecurity.SelectedIndex < 1)
            {
                errMsg  = "密级不能为空!";
                return;
            }
            else
            {
                //若有密级
                if (this.ddlSecurity.SelectedIndex != 1)
                {
                    if (this.ddlKeepSecurityTime.SelectedIndex < 1)
                    {
                        errMsg = "保密期限不能为空!";
                        return;
                    }
                }
            }
            ArchiveMangeModal.EQUIPMENT_ARCHIVEDataTable sourceTable = DocumentArchiveService.GetAllDocumenArchivetDataById(ArchiveID);
            ArchiveMangeModal.EQUIPMENT_ARCHIVERow sourceRow = sourceTable.Rows[0] as ArchiveMangeModal.EQUIPMENT_ARCHIVERow;

            DataSet ds = new DataSet();
            ArchiveMangeModal.EQUIPMENT_ARCHIVEDataTable dtArchive = new ArchiveMangeModal.EQUIPMENT_ARCHIVEDataTable();
            ArchiveMangeModal.EQUIPMENT_ARCHIVERow row = dtArchive.NewEQUIPMENT_ARCHIVERow();
            row.ItemArray = sourceRow.ItemArray;

            if (this.txtBoxNum.Text == "未装盒")
            {
                row.BOXNUM = null;
            }
            else
            {
                row.BOXNUM = this.txtBoxNum.Text;
            }

            row.LASTUPDATETIME = DateTime.Now;
            row.LASTUPDATEUSER = this.CurrentUser.User_ID;

            row.F_KEEPTIME = this.ddlKeepTime.SelectedValue;
            row.F_CARRIERTYPE = this.ddlCarrierType.SelectedValue;
            row.F_SECURITYTYPE = this.ddlSecurity.SelectedValue;
            row.F_KEEPSECURITYTIME = this.ddlKeepSecurityTime.SelectedValue;
 
            row.FILEORGID = this.txtFileOrgName.Text;
            if (DateTime.TryParse(this.txtFilTime.Text.Trim(), out o_time))
            {
                row.FILETIME = o_time;
            }
            else
            {
                row.SetFILETIMENull();
            }
            row.FULLFONDSNUM = this.txtFullFondsNum.Text;
            row.EXPANSIONINFO = null;
            int pageNum, mainBodyNum, fileNum;
            int.TryParse(this.txtPageNum.Text.Trim(), out pageNum);
            int.TryParse(this.txtMainBodyNum.Text.Trim(), out mainBodyNum);
            int.TryParse(this.txtFileNum.Text.Trim(), out fileNum);
            row.FILENUM = fileNum;
            row.PAGENUM = pageNum;
            row.PUBLISHORGID = this.txtPublishOrgID.Text;
            row.MAINBODYNUM = mainBodyNum;
            row.TITLE = this.txtTitle.Text;
            row.SUMMARY = this.txtSummary.Text;
            row.STORAGETYPE = this.txtStorageType.Text;
            row.REMARK = this.txtRemark.Text;
            row.HUJIANHAO = this.txtHUjianhao.Text;
            row.STARTTIME = Convert.ToDateTime(this.txtStartTime.Text);
            row.ENDTIME = Convert.ToDateTime(this.txtEndTime.Text);
            row.TYPENUM = this.txtTypeNum.Text;
            dtArchive.NewRow();
            dtArchive.Rows.Add(row);

            dtArchive.AcceptChanges();
            row.SetModified();
            ds.Tables.Add(dtArchive);
            try
            {
                bool bResult = DocumentArchiveService.SaveData(ds);
                bResult = bResult & SaveAttachment() & SavePageFile();
                WriteUserLog("用户" + CurrentUser.User_Name + "修改了设备类的标题为" + row.TITLE + "的档案", OracleLogType.ArchiveManage);
            }
            catch (Exception ex)
            {
                errMsg = "保存失败,错误信息:" + ex.Message;
            }
        }

        private void WorkFlowStart(ArchiveMangeModal.EQUIPMENT_ARCHIVERow row)
        {
            WorkFlowModel oWorkFlowModel = new WorkFlowModel();
            int originaleStatusID = new WorkFlowManager().GetOriginalStastuIDByTableID((ArchiveTableEnum)int.Parse(ReqArchiveType));
            oWorkFlowModel.FromStatusID = originaleStatusID;//当前数据的状态
            oWorkFlowModel.FromUserID = new Guid(this.CurrentUser.User_ID);//当前用户的 userId ，从session取
            oWorkFlowModel.TableID = int.Parse(ReqArchiveType);
            oWorkFlowModel.RecordID = new Guid(row.DATAID);
            oWorkFlowModel.OperateLogID = Guid.NewGuid();
            //oWorkFlowModel.CommentMessage = "上报时候不需要，审核时候带审核意见";

            WorkFlowMessageStatusRuleListCache ruleCache = new ArchiveCacheFacade().GetStatusRuleCache();

            WorkFlowMessageStatusRule rule = ruleCache.GetRuleByStatusIDAndOperateName(oWorkFlowModel.FromStatusID, hiddenCurrentFlowName.Value);
            oWorkFlowModel.OperateID = rule.OperateID;//取驱动的ID
            WorkFlow oWorkFlow = new WorkFlow();
            //oWorkFlow.FlowProcess(oWorkFlowModel);//有操作，就用。涉及流程
            oWorkFlow.FlowStart(oWorkFlowModel);//数据临时保存时候，用。不涉及流程
        }

        private bool SaveAttachment()
        {
            DataTable dt_Attach = this.attachArchive.GetSaveDataTable(this.attachArchive.ObjectID, this.attachArchive.ObjectTableName);
            IEquipmentService DocumentArchiveService = UContainer.Resolve<IEquipmentService>();
            return DocumentArchiveService.SaveAttach(dt_Attach, this.attachArchive.ObjectTableName, this.attachArchive.ObjectID,
                 this.attachArchive.AttachmentDBHelperString);
        }

        /// <summary>
        /// 保存卷内件信息(尚未完成)
        /// </summary>
        private bool SavePageFile()
        {
            string archiveid = ArchiveID;
            bool bReturn = false;
            IList<string> list = new List<string>();
            if (Session["ArchivePageFile"] != null)
            {
                Hashtable ht = (Hashtable)Session["ArchivePageFile"];
                if (ht.ContainsKey(ArchiveID))
                {
                    foreach (string value in ht.Values)
                    {
                        list.Add(value);
                    }
                }
            }
            IEquipmentService account = UContainer.Resolve<IEquipmentService>();
            bReturn = account.SavePageFile(list, archiveid);
            Session.Remove("ArchivePageFile");
            return bReturn;
        }


        #endregion
    }
}